from abc import ABC, abstractmethod


# todo 可结合迭代器模式，让链中的节点顺序可以灵活改变
class Examiner(ABC):
    @abstractmethod
    def check(self, article):
        pass


class ImageExaminer(Examiner):
    def check(self, article):
        is_image_violation = self._is_image_violation(article)
        if is_image_violation:
            print("图片违规")
            return True
        print("图片审核通过")
        return False

    def _is_image_violation(self, article):
        # 假设图片违规的逻辑
        return False  # 这里可以根据实际逻辑返回 True 或 False


class SensitiveExaminer(Examiner):
    def __init__(self, next_examiner: Examiner = None) -> None:
        self.next_examiner = next_examiner

    def check(self, article):
        is_sensitive_word_present = self._is_sensitive_word_present(article)
        if is_sensitive_word_present:
            print("包含敏感词")
            return True
        if self.next_examiner:
            return self.next_examiner.check(article)
        return False

    def _is_sensitive_word_present(self, article):
        # 假设包含敏感词的逻辑
        return False  # 这里可以根据实际逻辑返回 True 或 False


class BaseExaminer(Examiner):
    def __init__(self, next_examiner: Examiner = None) -> None:
        self.next_examiner = next_examiner

    def check(self, article):
        is_length_invalid = self._is_length_invalid(article)
        if is_length_invalid:
            print("字数不符合要求")
            return True
        if self.next_examiner:
            return self.next_examiner.check(article)
        return False

    def _is_length_invalid(self, article):
        # 假设字数不符合要求的逻辑
        return False  # 这里可以根据实际逻辑返回 True 或 False


# 示例使用
article = "123"

image_examiner = ImageExaminer()
sensitive_examiner = SensitiveExaminer(image_examiner)
base_examiner = BaseExaminer(sensitive_examiner)
base_examiner.check(article)
